-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest dereferencing on assignment to mutable borrow #61054
Conversation
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
cc @Centril on wording |
@bors r+ |
📌 Commit 1e3302d has been approved by |
Won't this suggestion trigger even if the type of the pointee and the assignee are different? let mut x = 0;
(&mut x) = None; // suggestion to consider dereferencing does not work |
I'll add a negative check to the test to avoid regressions, but by the time we hit this code we have already checked that the two types can be unified and that the left is a mutable borrow. |
@bors r- Until that test is added then :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a big, big fan of having a diagnostic for this as I make this mistake on a regular basis.
@@ -397,6 +398,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
} else { | |||
String::new() | |||
}; | |||
if let Some(hir::Node::Expr(hir::Expr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this addition the function is ~200+ LOC -- can we avoid making it bigger? =P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm focusing on slimming/splitting Parser
now. I'll move to other parts of the compiler once in done with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, just don't forget about it... =)
@bors r=zackmdavis added the test |
🙀 |
@bors r=zackmdavis |
📌 Commit 7fbbcfa has been approved by |
For the case in @mark-i-m's comment, the output is:
|
…avis Suggest dereferencing on assignment to mutable borrow Fix rust-lang#33570
Rollup of 6 pull requests Successful merges: - #59545 (Use arenas to avoid Lrc in queries #2) - #61054 (Suggest dereferencing on assignment to mutable borrow) - #61056 (tweak discriminant on non-nullary enum diagnostic) - #61082 (fix dangling reference in Vec::append) - #61086 (Box::into_unique: do the reborrow-to-raw *after* destroying the Box) - #61098 (Fix overflowing literal lint in loops) Failed merges: r? @ghost
Fix #33570